<?php

namespace App\Http\Controllers\Api;

use App\Models\Renting;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
    //用户信息入库
    public function userinfo(Request $request){
        //得到openid
        $openid = $request->get('openid');
        //得到表单数据,用户基本信息
        $data = $request->except('openid');
        //修改入库
        try {
            Renting::where('openid',$openid)->update($data);
            return ['status' => 0,'msg' => '修改成功','data'=>Renting::where('openid',$openid)->first()];
        }catch (\Exception $exception){
            return ['status' => 1006,'msg' => '修改失败'];
        }
    }

    //获取用户信息
    public function getuserinfo(Request $request){
        //获取openid
        $openid = $request->get('openid');
        return Renting::where('openid',$openid)->first();
    }

    //文件上传
    public function upfile(Request $request){
        if($request->hasFile('file')){
            $ret = $request->file('file')->store($request->get('openid'),'card');
            $pic = '/uploads/card/'.$ret;
            return ['status' => 0,'pic'=>$pic,'url'=>config('url.domain') . $pic];
        }
        return ['status'=>1005,'msg'=> '无图片上传'];
    }





}
